$.fn.dropdown = function () {
    var $selectMenu = $(this);

    //$selectMenu.hide();

    $('<div />').insertAfter($selectMenu);
    $($selectMenu).next().addClass('dropdown-list-container');
    $('.dropdown-list-container').append('<ul />');
    $('.dropdown-list-container ul').addClass('dropdown-list-options');

    var $options = $selectMenu.children();
    for (var i = 0; i < $options.length; i++) {
        $('.dropdown-list-options').append('<li />');
        $('.dropdown-list-options li')
            .last()
            .addClass('dropdown-list-option')
            .attr('data-value', i)
            .text($options[i].text);
    }

    var isMenuVisible = true;

    $('.dropdown-list-options').on('click', 'li', function () {
        var $clickedElement = $(this);
        $selectMenu
            .find(
                'option[value="' +
                (parseInt($clickedElement.attr('data-value')) + 1).toString() +
                '"]')
            .attr('selected', 'selected');

        if (isMenuVisible) {
            $('.dropdown-list-options li').hide();
            $($clickedElement).show();
            isMenuVisible = false;
        }
        else {
            $('.dropdown-list-options li').show();
            isMenuVisible = true;
        }
    });
};